package com.umakr.demo.controller;

import com.umakr.demo.model.Banji;
import com.umakr.demo.model.Teacher;
import com.umakr.demo.model.TeacherBanji;
import com.umakr.demo.service.BanjiSerivice;
import com.umakr.demo.service.TeacherBanjiService;
import com.umakr.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by yangliu on 2017/8/22.
 */
@Controller
@RequestMapping("/TeacherBanjiController")
public class TeacherBanjiController {
    @Autowired
    TeacherService teacherService;

    @Autowired
    BanjiSerivice banjiSerivice;

    @Autowired
    TeacherBanjiService teacherBanjiService;


    @RequestMapping("/showTeacherBanji")
    public String showTeacherBanji(){
        return "StudentManage/teacherbanji";
    }

    @RequestMapping("/teacherDate")
    @ResponseBody
    public List<Teacher> teacherDate(){
        List<Teacher> list = teacherService.showAll();
        return list;
    }

    @RequestMapping("/banjiDate")
    @ResponseBody
    public List<Banji> banjiDate(){
        List<Banji> list = banjiSerivice.showAll();
        return list;
    }


    @RequestMapping("/teacherShowBanji")
    @ResponseBody
    public List<Banji> teacherShowBanji(Long tid){
        List<Banji> list = teacherBanjiService.teacherShowBanji(tid);
        return list;
    }


    @RequestMapping("/allSelectedBanji")
    @ResponseBody
    public void allSelectedBanji(Long tid, @RequestParam(value = "str[]",required = false)String str[]){
//        删除所有的数据
        teacherBanjiService.deleteAll(tid);
        for(int i =0;i<str.length;i++){
            TeacherBanji teacherBanji = new TeacherBanji(tid,Long.parseLong(str[i]));
            teacherBanjiService.addAll(teacherBanji);
        }

    }

}
